package com.project.util;

import java.util.Date;
import java.util.Random;

/**
 * 
 * @author guyang
 * 生成编码
 */
public class GenerateCode {
	
	private final static String[] LOWERCASE = {"a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","d","u","v","w","x","y","z"};
	private final static String[] UPPERCASE = {"A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","D","U","V","W","X","Y","Z"};

	
	/**
	 * 生出随机数(长度自定义)
	 * @param n
	 * @return
	 */
	public static String randomCode(int n){
		String str = "";
		for(int i=0;i<n;i++){
			Random random = new Random();
			int num = random.nextInt(10);
			str += String.valueOf(num);
		}
		
		return str;
	}
	
	/**
	 * 生成一个随机字符串
	 * @param n
	 * @param status 默认是混合的 ，1、纯数字，2、纯小写，3、纯大写
	 * @return
	 */
	public static String randomWord(int n,String status){
		String str = "";
		
		Random random = new Random();
		for(int i=0;i<n;i++){
			int num = random.nextInt(26);
			
			if("1".equals(status)){
				str += random.nextInt(10);
			}else if("2".equals(status)){
				str += LOWERCASE[num];
			}else if("3".equals(status)){
				str += UPPERCASE[num];
			}else{
				int type = random.nextInt(3);
				if(type == 0 ){//数字
					str += String.valueOf(random.nextInt(9));
				}else if(type == 1){//小写
					str += LOWERCASE[num];
				}else if(type == 2){
					str += UPPERCASE[num];
				}
			}
		}
		
		return str;
		
	}
	
	/**
	 * 订单编码
	 * @param businessCode
	 * @return
	 */
	public static String getOrderCode(String businessCode){
		return "ORD-"+businessCode+DateUtil.format(new Date(), "yyyyMMdd")+randomWord(4,"1");
	}
	
	public static void main(String[] args) {
		System.out.println(getOrderCode("1"));
	}
	
}
